﻿@model www.Stertex.com.Models.SearchViewModel

@{
    ViewBag.Title = "Index";
}


<link href="@Url.Content("~/Content/themes/ui-lightness/jquery.ui.all.css")" rel="stylesheet" type="text/css" />
@*<link href="@Url.Content("~/Content/jqGrid/jquery-ui-jqgrid.css")" rel="stylesheet" type="text/css" />*@
<link href="@Url.Content("~/Content/jqGrid/ui.jqgrid.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jqGrid-4.3.1/js/i18n/grid.locale-en.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jqGrid-4.3.1/jquery.jqGrid.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>


@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        @*<legend>SearchViewModel</legend>*@

        <div class="editor-label">
            @Html.LabelFor(model => model.Firstname)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Firstname)
            @Html.ValidationMessageFor(model => model.Firstname)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Lastname)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Lastname)
            @Html.ValidationMessageFor(model => model.Lastname)
        </div>

        <p>
            <input type="submit" value="Search" id="Search" />
        </p>
    </fieldset>
}


@{
    var grid = new Lib.Web.Mvc.JQuery.JqGrid.JqGridHelper<Stertex.Models.ProfileViewModel>("Profiles",
    dataType: Lib.Web.Mvc.JQuery.JqGrid.JqGridDataTypes.Json,
    methodType: Lib.Web.Mvc.JQuery.JqGrid.JqGridMethodTypes.Post,
    pager: true,
    rowsNumber: 10,
    width:920,
    dataString:"x=454",
   caption: "Search profile",
    sortingName: "Id",
    sortingOrder: Lib.Web.Mvc.JQuery.JqGrid.JqGridSortingOrders.Asc,
    url: Url.Action("GetResults"),
    viewRecords: true
  ).Navigator(new Lib.Web.Mvc.JQuery.JqGrid.JqGridNavigatorOptions() { Search = true, View = false }
  );
    
}


@grid.GetHtml()


<script type="text/javascript">
    var search_result_grid = null;

  $(document).ready(function () {



        $("#Search").click(function() {
        
            if(search_result_grid == null)  {
                search_result_grid = @grid.GetJavaScript();
            }

            search_result_grid.setGridParam ({postData  :{Firstname: function () { return $("#Firstname").val() },
                                                          Lastname : function() { return $("#Lastname").val()}
                                                         } 
                                            });
            search_result_grid.trigger("reloadGrid");
            return false;
        });
    
    });

  $.onInitializeForm = function(formSelector){
        //alert(formSelector);
    }

    $.onAfterShowForm = function(formSelector) {
       
    }
</script>


